<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
    <title>芳小微宣</title>
    <!-- 引入 WeUI -->
    <link rel="stylesheet" href="http://res.wx.qq.com/open/libs/weui/0.4.0/weui.min.css">
    <script src="js/jquery.min.js"> </script>
    <script src="js/index.js"></script>
    <link rel="stylesheet" href="css/index.css">
</head>
<body>
<div style="width: 100%;height: auto; display: inline-block; margin-bottom: 70px;">
    <div class="weui_cells_title">最佳读者</div>
    <div id="ptoShow" style="display: inline-block">
    </div>
</div>
<div class="coverDiv">
    <div><img src="images/close.png" id="close"/> </div>
    <img src="" id="bigImg"/>
</div>
<div class="btnChoose">
    <div id="returnIndex">
        <img src="images/return.png" style="width: 25px;padding-top: 5px;"><br>
        <span>返回</span>
    </div>
    <div>
        <img src="images/add.png" id="addNew" style="width: 55px;position: relative;top: -12px;">
    </div>
    <div id="delete">
        <img src="images/delete.png" style="width: 20px;padding-top: 5px;"><br>
        <span>删除</span>
    </div>
</div>

<div class="weui_dialog_alert" style="display: none;">
    <div class="weui_mask"></div>
    <div class="weui_dialog">
        <div class="weui_dialog_hd"> <strong class="weui_dialog_title">警告</strong>
        </div>
        <div class="weui_dialog_bd">弹窗内容，告知当前页面信息等</div>
        <div class="weui_dialog_ft">
            <a href="javascript:;" class="weui_btn_dialog primary">确定</a>
        </div>
    </div>
</div>

<script>
    $.weui = {};
    $.weui.alert = function(options,sureEvent){
        options = $.extend({title: '提示', text: '提示内容'}, options);
        var $alert = $('.weui_dialog_alert');
        $alert.find('.weui_dialog_title').text(options.title);
        $alert.find('.weui_dialog_bd').text(options.text);
        $alert.on('touchend click', '.weui_btn_dialog', function(){
            $alert.hide();
            if(sureEvent){
                sureEvent();
            }
            //阻止事件冒泡
            // event.stopPropagation();
            return false;
        });
        $(".weui_mask").click(function(){
            $alert.hide();
        });
        $alert.show();
    };
    $(function(){
        $.ajax({
            type : "POST",
            url : path + "/api/weixin/getLibBestRead?token=" + window.localStorage.getItem("token"),
            data : {},
            dataType : 'json',
            async : true,
            success : function(msg) {
                if(msg.code == 0){
                    var imghtml = "";
                    for(var i=0;i<msg.bestRead.length;i++){
                        imghtml += '<div class="imgSin"> <img class="imgShow" src="'+ photoPath +  msg.bestRead[i].studentImg +'">' +
                                '<span class="wordSin">'+ msg.bestRead[i].className + msg.bestRead[i].studentName +'</span> ' +
                                '<img class="imgCheck" src="images/noselect.png" title="'+ msg.bestRead[i].id +'"> </div>';
                    }
                    $("#ptoShow").html(imghtml);
                }else if(msg.code == 501){
                    window.location.href = "login.html";
                }
            }
        })
    });

    var deleList = [];
    $("#ptoShow").on('click','.imgCheck',function(){
        if($(this).attr("src").indexOf("selected")>0){
            $(this).attr("src","images/noselect.png");
        }else {
            $(this).attr("src","images/selected.png");
        }
    });
    $("#ptoShow").on('click','.imgShow',function(){
        $(".coverDiv").css("display","block");
        $("#bigImg").attr("src",$(this).attr("src"));
        $("#bigImg").css("margin-top",($(".coverDiv").height()-$("#bigImg").height())/2);
    });
    $("#close").click(function(){
        $(".coverDiv").css("display","none");
    });



    $("#delete").click(function(){
        for(var i = 0;i< $(".imgCheck").length ; i++ ){
            if($(".imgCheck").eq(i).attr("src").indexOf("selected")>0){
                deleList.push($(".imgCheck").eq(i).attr("title"));
            }
        }
        if(deleList.length == 0){
            $.weui.alert({text: "请选择要删除的数据！"});
        }else{
            $.weui.alert({text: "确定删除吗?"},function(){
                //删除数据
                $.ajax({
                    type : "POST",
                    url : path + "/api/weixin/delLibBestRead",
                    data : {
                        "token" : window.localStorage.getItem("token"),
                        "ids" : JSON.stringify(deleList)
                    },
                    dataType : 'json',
                    success : function(msg) {
                        if(msg.code == 0){
                            window.location.href = "readBest.html";
                        }else if(msg.code == 501){
                            window.location.href = "login.html";
                        }
                    }
                })
            });
        }
    });
    $("#returnIndex").click(function(){
        window.location.href = "index.html";
    });
    $("#addNew").click(function(){
        window.location.href = "readBestAdd.html";
    });
</script>
</body>
</html>